home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP09 / RESOURC2.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  3.1 KB  |  100 lines

  1. /*-----------------------------------------------------------
  2.    RESOURC2.C -- Icon and Cursor Demonstration Program No. 2
  3.                  (c) Charles Petzold, 1996
  4.   -----------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. char      szAppName[] = "Resourc2" ;
  11. HINSTANCE hInst ;
  12.  
  13. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  14.                     PSTR szCmdLine, int iCmdShow)
  15.      {
  16.      HBITMAP    hBitmap ;
  17.      HBRUSH     hBrush ;
  18.      HWND       hwnd ;
  19.      MSG        msg ;
  20.      WNDCLASSEX wndclass ;
  21.  
  22.      hBitmap = LoadBitmap (hInstance, szAppName) ;
  23.      hBrush = CreatePatternBrush (hBitmap) ;
  24.  
  25.      wndclass.cbSize        = sizeof (wndclass) ;
  26.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  27.      wndclass.lpfnWndProc   = WndProc ;
  28.      wndclass.cbClsExtra    = 0 ;
  29.      wndclass.cbWndExtra    = 0 ;
  30.      wndclass.hInstance     = hInstance ;
  31.      wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  32.      wndclass.hCursor       = LoadCursor (hInstance, szAppName) ;
  33.      wndclass.hbrBackground = hBrush ;
  34.      wndclass.lpszMenuName  = NULL ;
  35.      wndclass.lpszClassName = szAppName ;
  36.      wndclass.hIconSm       = LoadIcon (hInstance, szAppName) ;
  37.  
  38.      RegisterClassEx (&wndclass) ;
  39.  
  40.      hInst = hInstance ;
  41.  
  42.      hwnd = CreateWindow (szAppName, "Icon and Cursor Demo",
  43.                           WS_OVERLAPPEDWINDOW,
  44.                           CW_USEDEFAULT, CW_USEDEFAULT,
  45.                           CW_USEDEFAULT, CW_USEDEFAULT,
  46.                           NULL, NULL, hInstance, NULL) ;
  47.  
  48.      ShowWindow (hwnd, iCmdShow) ;
  49.      UpdateWindow (hwnd) ;
  50.  
  51.      while (GetMessage (&msg, NULL, 0, 0))
  52.           {
  53.           TranslateMessage (&msg) ;
  54.           DispatchMessage (&msg) ;
  55.           }
  56.  
  57.      DeleteObject ((HGDIOBJ) hBrush) ;       // clean-up
  58.      DeleteObject ((HGDIOBJ) hBitmap) ;
  59.  
  60.      return msg.wParam ;
  61.      }
  62.  
  63. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  64.      {
  65.      static HICON hIcon ;
  66.      static int   cxIcon, cyIcon, cxClient, cyClient ;
  67.      HDC          hdc ;
  68.      PAINTSTRUCT  ps ;
  69.      int          x, y ;
  70.  
  71.      switch (iMsg)
  72.           {
  73.           case WM_CREATE :
  74.                hIcon = LoadIcon (hInst, szAppName) ;
  75.                cxIcon = GetSystemMetrics (SM_CXICON) ;
  76.                cyIcon = GetSystemMetrics (SM_CYICON) ;
  77.                return 0 ;
  78.  
  79.           case WM_SIZE :
  80.                cxClient = LOWORD (lParam) ;
  81.                cyClient = HIWORD (lParam) ;
  82.                return 0 ;
  83.  
  84.           case WM_PAINT :
  85.                hdc = BeginPaint (hwnd, &ps) ;
  86.  
  87.                for (y = cyIcon ; y < cyClient ; y += 2 * cyIcon)
  88.                     for (x = cxIcon ; x < cxClient ; x += 2 * cxIcon)
  89.                          DrawIcon (hdc, x, y, hIcon) ;
  90.  
  91.                EndPaint (hwnd, &ps) ;
  92.                return 0 ;
  93.  
  94.           case WM_DESTROY :
  95.                PostQuitMessage (0) ;
  96.                return 0 ;
  97.           }
  98.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  99.      }
  100.